package com.example.dicos.controller;

import com.example.dicos.config.CommonResult;
import com.example.dicos.entity.dot.TestDto;
import com.example.dicos.entity.dot.UpdateDto;
import com.example.dicos.entity.dot.batchDelete;
import com.example.dicos.service.TestService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "批量处理数据 Dome")
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private TestService testService;

    @PostMapping("/addTest")
    public CommonResult addTest(@RequestBody TestDto testDto) {

        return CommonResult.success(testService.addTest(testDto));
    }

    /**
     * 批量删除
     */
    @PostMapping("/batchDelete")
    public CommonResult ss(@RequestBody batchDelete batchDelete) {

        return CommonResult.success(testService.batchDelete(batchDelete));
    }

    /**
     * 批量更新
     */
    @PostMapping("/updates")
    public CommonResult updates(@RequestBody UpdateDto test) {

        return CommonResult.success(testService.updates(test));
    }

    /**
     * 多个对象进行更新操作 在连接数据后添加
     * &allowMultiQueries=true  表示允许多个更新操作
     * <p>
     * 出现的错误：
     * java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your
     * MySQL server version for the right syntax to use near 'update test
     * set `name`= '23131',
     * `age`= 0
     * ' at line 6
     *
     * @param test
     * @return
     */
    @PostMapping("/updatesTwo")
    public CommonResult updatesTwo(@RequestBody TestDto test) {

        return CommonResult.success(testService.updatesTwo(test));
    }
}
